package com.bignerdranch.android.ecar.sortlistview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bignerdranch.android.ecar.R;

import java.util.List;


/**
 * Created by Administrator on 2016/7/21.
 */
public class DrawerAdapter extends BaseAdapter {

    private Context mContext;
    private LayoutInflater mInflater;
    private List<String> mData;

    public DrawerAdapter(Context context, List<String> data) {
        mContext = context;
        mData = data;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHold hold = new ViewHold();

        if (convertView==null){
            convertView = mInflater.inflate(R.layout.drawer_item,null);
        }

        if (convertView.getTag()==null){
            hold.series = (TextView) convertView.findViewById(R.id.car_series);

            convertView.setTag(hold);
        }else {
            hold = (ViewHold) convertView.getTag();
        }

        hold.series.setText(mData.get(position));

        return convertView;
    }

    private static class ViewHold{
        private TextView series;
    }
}
